home *** CD-ROM | disk | FTP | other *** search
/ Fritz: All Fritz / All Fritz.zip / All Fritz / FILES / GRAPTIES / 256DRAW.LZH / EXAMPLE.C < prev    next >
C/C++ Source or Header  |  1991-10-23  |  2KB  |  81 lines

  1. /*
  2.   This Turbo C Code example is an example of a program that simply
  3.   loads the VGA256 device driver, goes into graphics mode, loads an
  4.   image from disk (one with a palette), and displays it.
  5.  
  6.   Function Load256Image will load an image file and place it in the variable
  7.   pointer image.  If you are a registered user feel free to use Load256Image
  8.   in your programs.
  9.  
  10.   To run this demonstration, you will need to have Turbo C (not sure which
  11.   version, we used Turbo C++), as well as the Borland VGA256.BGI device
  12.   driver.  This driver is available as shareware, usually bundled with the
  13.   BGI Toolkit.  The VGA256.BGI driver is not distributed with the 256 Draw
  14.   Program.
  15. */
  16.  
  17. #include <graphics.h>
  18. #include <stdio.h>
  19. #include <alloc.h>
  20. #include <io.h>
  21. #include <fcntl.h>
  22. #include <dos.h>
  23.  
  24. #define VGA320X200 0
  25.  
  26. int huge DetectVGA256(void);
  27. unsigned char *load256image(char *filename);
  28.  
  29. void main(void)
  30. {
  31.     int gd=DETECT, gm, i;
  32.     unsigned char *image;
  33.  
  34.     installuserdriver("VGA256",DetectVGA256);
  35.     initgraph(&gd,&gm,"");
  36.  
  37.     image=load256image("parrot.vga");
  38.  
  39.     putimage(0,0,image,COPY_PUT);
  40.  
  41.     getch();
  42.     closegraph();
  43.     free(image);
  44. }
  45.  
  46. int huge DetectVGA256(void)
  47. {
  48.     return(0);
  49. }
  50.  
  51. unsigned char *load256image(char *filename)
  52. {
  53.     int fp, color;
  54.     unsigned int xsize, ysize, vgasize;
  55.     long size;
  56.     unsigned char *image;
  57.  
  58.     fp=open(filename, O_RDONLY | O_BINARY);
  59.     size=filelength(fp);
  60.     image=malloc(size);
  61.     read(fp,image,size);
  62.     close(fp);
  63.  
  64.     xsize=*(image+0)+*(image+1)*256;
  65.     ysize=*(image+2)+*(image+3)*256;
  66.     vgasize=imagesize(1,1,xsize,ysize);
  67.  
  68.     if (size > vgasize)
  69.     {
  70.         for (color=0; color < 256; color++)
  71.         {
  72.             outportb(0x3C8,color);
  73.             outportb(0x3C9,*(image+vgasize+(color*3)+0));
  74.             outportb(0x3C9,*(image+vgasize+(color*3)+1));
  75.             outportb(0x3C9,*(image+vgasize+(color*3)+2));
  76.         }
  77.         image=realloc(image,vgasize);
  78.     }
  79.     return(image);
  80. }
  81.